$(function () {
    initEvent();
});

function initEvent() {
    $("#confirmClick").off('click').on('click', function () {
        btn_Submit();
    });
}

function btn_Submit() {
    var order_num = $("#order_num").text();
    var p_set_amount = $("#p_set_amount").val();
    var p_id = $("#confirmClick").attr("p_id");
    //分销人员id
    var qrcode_id = $("#confirmClick").attr("qrcode_id");

    var openid = $("#confirmClick").attr("openid");

    //是否购买保险
    var is_insurance = $('.p_insurance_price').is(':checked');
    if(is_insurance){
        //保险费金额
        var p_insurance_price = $("#p_set_amount").attr('p_insurance_price');
        if(p_set_amount*1 < p_insurance_price*1){
            falert('合计金额不能小于'+p_insurance_price+'元');
            return false;
        }
    }

    if (!order_num && !p_id) {
        falert('订单有误！');
        return false;
    }

    if (order_num && p_id) {
        var datas = {
            interface:'IcbcPay@payOrder',
            order_num: order_num,
            p_id: p_id,
            qrcode_id:qrcode_id,
            openid:openid,
            p_set_amount:p_set_amount,
        };
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    //下单成功
                    if(is_insurance){
                        location.href = '/insuranceInfo?order_num='+data.result.order_num+'&p_id='+p_id;
                    }else{
                        location.href = '/pay/?order_num='+data.result.order_num;
                    }
                } else if (data.status == '5000') {
                    falert(data.msg);
                } else if (data.status == '5003') {
                    falert(data.msg);
                }
            }
        });
    }
}
